package com.myaxuan.util;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by pc255 on 2018/4/24.
 */
public class Checkout {

	public static void main(String[] args) {
		List<Integer> pigs= new ArrayList<>();
		Integer [] pigs2= new  Integer[10];
		for (int i=1;i<=10;i++){
			pigs.add(i);
			pigs2[i-1]=i;
		}

/*		String result=lastPig(pigs);
		System.out.println(result);*/
		String  result=lastPig(pigs2);
		System.out.println(result);
			}




	public  static String  lastPig(List<Integer> pigs){
		int length = pigs.size();
		int n = 0;
		if (length == 1){
			return pigs.toString();
		}else{
			for (int i=0;i < length; i++){
				if(i == 0){
					System.out.println("移除" + pigs.get(i));
					pigs.remove(i);
					n++;
				}
				if(i%2 == 0  && i != 0) {
					System.out.println("移除" + pigs.get(i-n));
					pigs.remove(i-n);
					n++;
				}
			}
			lastPig(pigs);
		}
		return pigs.toString();
	}

	public  static String  lastPig(Integer [] pigs){
		int length = pigs.length;
		if(length == 1){
			return pigs.toString();
		}else{
			if(pigs[0] != 0){
				for (int i=0;i < length; ){
					System.out.println("杀死第" + pigs[i]+"只猪");
					pigs[i]=0;
					i=(i+1)*2+1;
				}
				lastPig(pigs);
			}else{
				for (int i=0;i < length; ){
					if(pigs[i]!=0){
						System.out.println("杀死第" + pigs[i]+"只猪");
						pigs[i]=0;
						i=(i+1)*2+1;
					}else{
						i = i + 1;
					}
				}
				lastPig(pigs);
			}
		}
		return null;
	}


	public static int sumRabbit(int num){
		int a,b,c;

		if(num== 1 || num== 2){
			return 1 ;
		}else{
			a = sumRabbit(num-1);
			b = sumRabbit(num-2);
			c = a+b;
			System.out.println("a="+a+",b="+b+"和等于"+c);
			return a+b;
		}
	}

}
